package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.TowerWarning;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/25
 *
 * 塔吊详情违章列表适配器
 */

public class TowerDataWarningListAdapter extends RecyclerAdapter<TowerWarning, TowerDataWarningListAdapter.TowerDataWarningListViewHolder> {

    public TowerDataWarningListAdapter(Context context, List<TowerWarning> dataList) {
        super(context, dataList);
    }

    @Override
    public TowerDataWarningListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_tower_data_list_warning, null);
        return new TowerDataWarningListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TowerDataWarningListViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class TowerDataWarningListViewHolder extends RecyclerAdapter.BaseViewHolder<TowerWarning>{
        @BindView(R.id.tower_warning_type_tv)
        HXTextView towerWarningTypeTv;
        @BindView(R.id.tower_warning_tv)
        HXTextView towerWarningTv;
        @BindView(R.id.create_time_tv)
        HXTextView createTimeTv;

        public TowerDataWarningListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            final TowerWarning towerWarning = dataList.get(position);
            if(towerWarning.getType().equals("预警")){
                towerWarningTypeTv.setEnabled(true);
                towerWarningTypeTv.setText("预警");
            }else {
                towerWarningTypeTv.setEnabled(false);
                towerWarningTypeTv.setText("报警");
            }
            towerWarningTv.setText(towerWarning.getClassify() + "  " + towerWarning.getValue());
            createTimeTv.setText(towerWarning.getAcquisitionTime());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(towerWarning);
                }
            });
        }
    }
}
